﻿using blackhouse.WebNemo.Business;
using blackhouse.WebNemo.Business.Groups;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace blackhouse.WebNemo.Web.Nemo.Manager {
    public partial class Group : System.Web.UI.Page {

        #region Fields

        private Factory factory = Factory.Instance();
        private IGroup group;
        private NemoUrl stateUrl;

        #endregion

        #region Event Handlers

        protected override void OnPreInit(EventArgs e) {
            base.OnPreInit(e);

            WebNemoUtils.ChangeSkinForCurrentMode(this);
        }

        protected override void OnLoad(EventArgs e) {
            base.OnLoad(e);

            this.SetScenario();
            this.PopulateView();
        }

        #endregion

        #region Methods

        private void SetScenario() {
            this.stateUrl = new NemoUrl();
            if (this.stateUrl.GroupId > 0)
                this.group = this.factory.GetGroup(this.stateUrl.GroupId);
        }

        private void PopulateView() {
            NemoJsLibrary njl = new NemoJsLibrary();
            njl.IncludePopup();
            njl.IncludeScroller();

            this.ltlGroupName.Text = this.group.Name;
            this.ltlSystemName.Text = this.group.SystemName;

            this.lnkCancel.NavigateUrl = this.GetCancelUrl();
        }

        private string GetCancelUrl() {
            if (this.stateUrl.HaveReturnUrl)
                return this.stateUrl.RequestReturnUrl;
            else {
                return "~/Manager/";
            }
        }

        #endregion

    }
}